<?php
/**
 * 帐号信息 - JBlog
 *
 * @copyright (c) 2008-2012 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id: Account.php 30 2012-10-15 06:08:28Z lisijie86@gmail.com $
 */
class AccountController extends BaseController {
	
	protected function _init_() {
		$this->setTitle(JBlog::config('blog.name'));
	}

	public function indexAction() {
	
	}
	
	public function loginAction() {
		$this->setTitle(__('用户登录'));
		if ($this->userid > 0) $this->redirect(URL('index.index'));
		if ($this->input->isPost()) {
			$account = $this->input->account;
			$password = $this->input->password;
			if (Validate::isEmpey($account) || Validate::isEmpey($password)) {
				$this->assign('errmsg', __('请输入帐号密码'));
			} else {
				$field = Validate::isEmail($account) ? 'email' : 'username';
				$user = $this->db->get($account, $this->db->getTable('user'), $field);
				if (!$user) {
					$this->assign('errmsg', __('用户不存在'));
				} else {
					if ($user['password'] != md5($password)) {
						$this->assign('errmsg', __('您输入的密码有误'));
					} else {
						Auth::set($user['id'], $user['password']);
						$this->redirect(URL('index.index'), 0);
					}
				}
			}
		}
		$this->display();
	}
	
	public function logoutAction() {
		Auth::destory();
		$this->message(__('你已经安全退出登录，现在转到首页...'), './');
	}

	public function registerAction() {
		if ($this->input->isPost()) {
			
		}
		$this->display();
	}
}
?>